package keke;

import java.util.Scanner;
class Repo{
	private String[] str;
	private int size;
	private int i = 0;
	private boolean flag = true;
	public Repo(String times) {
		this.str=times.split(" ");
	}
	int getSize(){
		size=str.length-i;
		return size;
	}

	public synchronized void run1(){
		while(getSize()>0){
			if(flag==false){
				try{  
					wait();  
				}catch(InterruptedException e){  
					e.printStackTrace();  
				}
			}
			System.out.println(Thread.currentThread().getName() + " finish "+str[i++]);
			flag=false;
			notify();
		}
	}
	public synchronized void run2() {
		while (getSize()>0){
			if(flag==true){
				try{  
					wait();  
				}catch(InterruptedException e){  
					e.printStackTrace();  
				} 
			} 
			System.out.println(Thread.currentThread().getName() + " finish "+str[i++]);
			flag=true;
			notify();
		}
	}
}
class Worker1 implements Runnable{
	private Repo repo;
	
	public Worker1(Repo repo) {
		super();
		this.repo = repo;
	}
	@Override
	public synchronized void run() {
		repo.run1();
	}
	
}
class Worker2 implements Runnable{
	private Repo repo;
	
	public Worker2(Repo repo) {
		super();
		this.repo = repo;
	}

	@Override
	public synchronized void run() {
		repo.run2();
	}
	
}
public class Main0706 {
    public static void main(String[] args) throws InterruptedException {
        Scanner sc = new Scanner(System.in);
        Repo repo = new Repo(sc.nextLine());
        Thread t1 = new Thread(new Worker1(repo));
        Thread t2 = new Thread(new Worker2(repo));
        t1.start();
        Thread.yield();
        t2.start();
        sc.close();
    }
}

